import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import vueJsx from '@vitejs/plugin-vue-jsx'

const lastBuildVersion = function () {
  let date = new Date()
  let year = date.getFullYear() + ''
  let month = date.getMonth() + 1 + ''
  let day = date.getDate() + ''
  let hour = date.getHours() + ''
  let minutes = date.getMinutes() + ''
  let second = date.getSeconds() + ''
  return `${year.substr(2)}.${month.padStart(2, '0')}.${day.padStart(2, '0')}.${hour.padStart(
    2,
    '0'
  )}.${minutes.padStart(2, '0')}.${second.padStart(2, '0')}`
}

const __APP_INFO__ = {
  lastBuildVersion: lastBuildVersion()
}

// https://vitejs.dev/config/
export default defineConfig({
  css: {
    preprocessorOptions: {
      // 导入scss预编译程序
      scss: {
        additionalData: `@use "@/assets/index.scss" as *;@use "@/assets/vant.scss" as *;`
      }
    }
  },

  publicDir: 'public',
  plugins: [
    vue(),
    vueJsx()
    // eslint()
  ],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src')
    }
  },
  server: {
    cors: true,
    hostname: '0.0.0.0',
    port: 3721,
    proxy: {
      '/apis': {
        target: `http://suzamdsltlab002:8095/`,
        changeOrigin: true,
        rewrite: path => path.replace(/^\/apis/, '/apis'),
        ws: true
      }
    },
    hmr: true
  },
  define: {
    __APP_INFO__: JSON.stringify(__APP_INFO__)
  }
})
